import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../.././services/http.service';
import { ActivatedRoute, Params } from '@angular/router';
import { WebsocketService } from '../../../services/websocket.service';
import { Router } from "@angular/router";
import { LoginInfoService } from '../../.././services/login-info.service';
@Component({
  selector: 'app-upload-img',
  templateUrl: './upload-img.page.html',
  styleUrls: ['./upload-img.page.scss'],
})
export class UploadImgPage implements OnInit {
  constructor(public router:Router, 
    public HttpService: HttpService , 
    public activeRoute: ActivatedRoute,  
    public websocket: WebsocketService,
    public LoginInfoService: LoginInfoService,) {

   }
  
  flag=true;
  public userId:any
  public clImg:any=[]
  ngOnInit() {
    this.seach()
    this.userId=JSON.parse(localStorage.getItem('userInfo')).idCard
    this.activeRoute.queryParams.subscribe((params: Params) => {
      console.log(params)
          if(params.object=="200"){
            this.flag=true;
          }
    });
    

    // this.activeRoute.queryParams.subscribe((params: Params) => {
    //           if(params.object=="200"){
                  
    //           }
    // });

  }

  scanner(){
    this.router.navigate(['/mycenter/uploading/scannner'], {
      queryParams: {
     id: "2"
   }
 })
  }
  send(){
    let arr = [];
    for(let item of this.clImg){
      if(item.isChecked == true){
        arr.push(item.url)
      }
    }
    this.websocket.sendMessage({
      userId: this.LoginInfoService.getlocal('user').idCard,
      code:"1100",
      info: arr
    })
    // let idCard= JSON.parse(localStorage.getItem('userInfo')).idCard;
    // let imglist=[];
    // for(let item of this.clImg){
    //   imglist.push( item.url);
    // }
    // let p =  {"files": imglist, idCard:JSON.parse(localStorage.getItem('userInfo')).idCard}
    // console.log(p)
    // this.HttpService.uploadFilesUrl(p).then(res=>{
    //   console.log(res,'+++++++++')
    //   if(res['code']==200){
      
    //   }else{
    //     console.log("查询失败")
    //   }
    // })
  }
  
 
   
  seach(){
  //  let idCard= JSON.parse(localStorage.getItem('userInfo')).idCard
    let p = {
      userId: this.LoginInfoService.getlocal('user').idCard
    }
    this.HttpService.get_uploadCl(p).then(res=>{
      console.log(res,'+++++++++')
    
      if(res['code']==200){
        for(let i of res['item']){
          i['isChecked'] = true;
        }
        this.clImg = res['item'];
      }else{
        console.log("查询失败")
      }
    })
}
}
